﻿using System;
using System.Diagnostics;
using System.Text;
using System.Xml;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TfsGiggle.Core.UnitTest
{
    [TestClass()]
    public class ScheduleSuggesterTest
    {
        /// <summary>
        ///A test for getting time intervals for suggested times where best to schedule jobs
        ///</summary>
        [TestMethod()]
        public void MustGetIntervalsOfEqualSize()
        {
            var now = DateTime.Now;
            var nowSecond = now.AddHours(12);
            ScheduleSuggester.AddEvent(now);
            ScheduleSuggester.AddEvent(nowSecond);

            var result = ScheduleSuggester.GetTimeslots();
            Assert.AreEqual(result.Count, 2, "Expected number of intervals must be returned");
            Assert.AreEqual(result[0].Item2, result[1].Item2, "The durations must be equal");

            ScheduleSuggester.Clear();
            now = DateTime.Now;
            nowSecond = now.AddHours(8);
            var nowThird = now.AddHours(16);
            ScheduleSuggester.AddEvent(now);
            ScheduleSuggester.AddEvent(nowSecond);
            ScheduleSuggester.AddEvent(nowThird);

            result = ScheduleSuggester.GetTimeslots();
            Assert.AreEqual(result.Count, 3, "Expected number of intervals must be returned");
            Assert.AreEqual(result[0].Item2, result[1].Item2, "The durations must be equal");
            Assert.AreEqual(result[1].Item2, result[2].Item2, "The durations must be equal");

            ScheduleSuggester.Clear();
            now = DateTime.Now;
            nowSecond = now.AddHours(8);
            nowThird = now.AddHours(16);
            var nowFourth = now.AddMinutes(5);
            ScheduleSuggester.AddEvent(now);
            ScheduleSuggester.AddEvent(nowSecond);
            ScheduleSuggester.AddEvent(nowThird);
            ScheduleSuggester.AddEvent(nowFourth);

            result = ScheduleSuggester.GetTimeslots();
            Assert.AreEqual(result.Count, 4, "Expected number of intervals must be returned");
            Assert.AreEqual(result[0].Item2, result[1].Item2, "The durations must be equal");
            Assert.AreEqual(result[3].Item2, 5, "Sorting must ensure that durations are equal");
        }
    }
}
